package com.zhxh.nzpos.api;

import org.ksoap2.serialization.SoapObject;

import com.zhxh.nzpos.api.exception.AuthenticationException;
import com.zhxh.nzpos.api.exception.AuthorizationException;
import com.zhxh.nzpos.api.exception.CommunicationException;
import com.zhxh.nzpos.model.Sellout;


public class ConnectorSale {

	private KSoapExecutor soap;
	
	public ConnectorSale(){
		
		soap = new KSoapExecutor();
	}
	
	public boolean submitSaleInfo(Sellout sellout, String posId, String CardID, String buyerId)
	        throws CommunicationException, AuthorizationException,
	        AuthenticationException {

		SoapObject getProjects = SoapObjectBuilder.start()
		        .withMethod("SubmitSaleInfo")
		        .withProperty("Key", "3e6f5018cd")
		        .withProperty("POSID", posId)
		        .withProperty("CardID", CardID)
		        .withProperty("NoteID", sellout.getOrderId())
		        .withProperty("GoodName", sellout.getGoodId())
		        .withProperty("CategoryID", sellout.getCategoryId())
		        .withProperty("Selldate", sellout.getSellDate())
		        .withProperty("Price", ""+sellout.getTotal())
		        .withProperty("Count", sellout.getCount())
		        .withProperty("Units", sellout.getUnits())
		        .withProperty("Specification", sellout.getSpecification())
		        .build();

		@SuppressWarnings("unchecked")
		SoapObject vc = null;
		try {
			vc = (SoapObject) soap.execute(getProjects);
			System.out.println("#####################vc="+vc);
		} catch (org.apache.http.auth.AuthenticationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (vc == null) return false;


		if ("true".equals(vc.toString())) {
			return true;
		}
		return false;
	}

}
